package com.bc.web.model;

import com.bc.common.basemodel.BaseWxClear;
import com.bc.common.message.WxgjClearingResp;
import com.fs.common.extend.FSSearchCondition;
import com.fs.common.extend.FSSqlHelper;
import com.fs.common.util.FSIDGenerate;
import com.jfinal.plugin.activerecord.Page;

@SuppressWarnings("serial")
public class WxClear extends BaseWxClear<WxClear>{
	public static final WxClear dao = new WxClear().dao();
	
	public static void createClear(WxgjClearingResp resp, String subMerchCode) {
		WxClear wxClear = new WxClear();
		wxClear.setDateEnd(resp.getDate_end());
		wxClear.setDateStart(resp.getDate_start());
		wxClear.setDateSettlement(resp.getDate_settlement());
		wxClear.setFbatchno(resp.getFbatchno());
		wxClear.setId(FSIDGenerate.getUUID());
		wxClear.setMerchCode(resp.getMerchCode());
		wxClear.setOrgCode(resp.getOrgCode());
		wxClear.setPayFee(Long.parseLong(resp.getPay_fee()));
		wxClear.setPayNetFee(Long.parseLong(resp.getPay_net_fee()));
		wxClear.setPoundageFee(Long.parseLong(resp.getPoundage_fee()));
		wxClear.setRefundFee(Long.parseLong(resp.getRefund_fee()));
		wxClear.setSettlementFee(Long.parseLong(resp.getSettlement_fee()));
		wxClear.setSettlementfeeType(resp.getSettlementfee_type());
		wxClear.setUnsettlementFee(Long.parseLong(resp.getUnsettlement_fee()));
		wxClear.setWxSubMerchCode(subMerchCode);
		wxClear.save();
	}
	
	public Page<WxClear> search(FSSearchCondition sc) {
		int pageNumber = sc.page.getPageNum();
		int pageSize = sc.page.getNumPerPage();
		FSSqlHelper sql = new FSSqlHelper(" from wx_clear WHERE 1 = 1");
		sql.date("date_settlement", sc.getStr("createDateStart"), sc.getStr("createDateEnd"));
		sql.equals("orgCode", sc.getStr("orgCode"));
		sql.equals("merchCode", sc.getStr("merchCode"));
		sql.orderBy("date_settlement", "desc");
		return super.paginate(pageNumber, pageSize, "select *", sql.toString(), sql.getParams());
	}
	
}
